<?php
/**
 * Created by PhpStorm.
 * User: eeo
 * Date: 2017/7/6
 * Time: 16:17
 */

namespace App\Http\Controllers\Marketing;

use App\Model\Marketing\AboutUs;
use Illuminate\Http\Request;
use Laravel\Lumen\Routing\Controller as BaseController;
use App\Http\Controllers\MessagePacket;


class AboutUsController extends BaseController
{

    use MessagePacket;

    public function getOne($id)
    {
        $id = 1;
        $obj = AboutUs::find($id);
        if(empty($obj)){
            return $this->fail($obj, '数据不存在');
        }
        return $this->success($obj);
    }

    public function add(Request $request){
        $obj = new AboutUs($request->all());
        if(!$obj->save()){
            return $this->fail($obj, '数据不存在');
        }
        return $this->success($obj);

    }

    public function update(Request $request)
    {
        $id = 1;
        $obj = AboutUs::find($id);
        if(!$obj){
            $obj = new AboutUs();
        }
        foreach ($request->all() as $key=>$val){
            $obj->$key = $val;
            $obj->id = 1;
        }
        if(!$obj->save()){
            return $this->fail($obj, '数据不存在');
        }
        return $this->success($obj);
    }

    public function  delete($id){
        if(AboutUs::destroy($id)){
            return $this->success(true);
        }
        return $this->fail(false,'删除失败');
    }

}